app.controller("fee",function($scope,$uibModal,$rootScope,del,$state,get,$stateParams,Upload ){
	
            //提交
            $scope.submit = function () {
                $scope.upload($scope.file);
            };
            $scope.upload = function (file) {
                $scope.fileInfo = file;
                Upload.upload({
                	 method:'POST',
                    //服务端接收
                    url: localStorage.getItem("Url")+'fee/import',
                    //上传的同时带的参数
                    file: file
                }).progress(function (evt) {
                	
                    //进度条
                    //var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                   // console.log('progess:' + progressPercentage + '%' + evt.config.file.name);
                }).success(function (data, status, headers, config) {
                	if(data.error!=null){
                		$rootScope.open(data.error);
                	}else{
                		$rootScope.open(data.data);
                	}
                	
                	$state.go("home.fee",{page:$scope.pageNum},{
				     		reload:true
				     	})
                    //上传成功
                    //console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
                }).error(function (data, status, headers, config) {
                    //上传失败
                    $rootScope.open(data.data);
                });
            };
	
	
	
		get.list("dictionary/subjectDic").then(function(e){
			$scope.itemArray = e
			$scope.itemArray.unshift({
				diName:"全部",
				diId:null
			})
				$scope.selected={
					value:{
						diName:"全部",
						diId:null
					}
				}
		})
	$scope.search=function(i){
		if($scope.selected==''||$scope.selected==null){
			$scope.selected={value: {
				diId:null
			}
			}
		}
		var param={
			pageNum:i||'1',
			pageSize:8,
			key:$scope.key||null,
			subject:$scope.selected.value.diId||null,
			startTime:$scope.startTime,
			endTime:$scope.endTime
		}
		get.list("fee/all",param).then(function(e){
			$scope.list=e.list
			$scope.pageSize = e.pageSize; //每页多少条
			$scope.totalNum = e.pageCount; //总共多少页
			$scope.totalSize =e.totalNums; //总共多少条   
			$scope.pageNum = e.pageNum; //当前页面
		})
		
   	
		
	
	}


	$scope.pageUp=function(){//跳转页码
       	if ($scope.tj.page>$scope.totalNum) {
       		$scope.tj.page=$scope.totalNum
       	} else if($scope.tj.page<1){
       	$scope.tj.page=null
       	}
       }//pageUp
   $scope.toPage=function(i){//点击跳转
       i=i||$scope.tj.page
       	$scope.search(i)
       	$scope.tj.current=$scope.tj.page;//页码调整
   }//toPage
   if($stateParams.page!=null){
			$scope.tj={
				page:$stateParams.page
			}
		 $scope.toPage($stateParams.page)
	}else{
			$scope.search();
	}
   /**
	 * 删除
	 */
	$scope.modelClick = function(id) { //单删
	$uibModal.open({ //模态框
		animation: true,
		templateUrl: 'myModalDel.html',
		size: 'sm',
		 backdrop: 'static' ,
		controller: function($uibModalInstance) {
			var $ctrl = this;
				$ctrl.state = true;
			$ctrl.ok = function() {
				del.list("fee/del",{frId:id}).then(function(e){
					$uibModalInstance.close();
					$rootScope.open(e);
					$state.go("home.fee",{page:$scope.pageNum},{
				     		reload:true
				     	})
				});
				
			}; //ok  
			$ctrl.cancel = function() {
				$uibModalInstance.close();
			};
		}, //controller
		controllerAs: '$ctrl'
	})
	}
})
